#!/usr/bin/perl -w
##############################################################################
#
# mftp.pl
# =======
#
# Author: Steven Liang <stliang@gmail.com>
#
# Purpose:
#   FTP one of more files to a server
#
# Assumptions:
#
#   This mftp.pl utility uses network nodes in a setup object
#
# Steps:
#
#   1.) Instantiate a localhost object and call it Mylocalhost
#   2.) Upload some files by using the localhost's ftp command
#   3.) Report the number of files successfully uploaded
#
# Expected result:
#
#   Expect all files to be successfully uploaded
#
##############################################################################

package main;
$VERSION = 1.01;

# If the PERLLIB environment variable is not set like
# "export PERLLIB=<lib directory>" then uncomment the
# following two lines:
# use FindBin qw($Bin); 
# use lib "$Bin/./lib";
use Setup_B;

my $mySetup = undef;
my $ftpServerIP = "172.16.15.15";
my $ftpUserName = "target";
my $ftpPassword = "password";

if ((defined $ENV{'PAT_ROOT'}) && (defined $ENV{'PAT_LOG'})) {
  # Instantiate a Setup_B object
  $mySetup = Setup_B->new();

  # Start a telnet session to target host
  $mySetup->{localhost}->openTelnet();

  # Log the entire telnet session to a file
  $mySetup->{localhost}->log($ENV{'PAT_LOG'} . "test_ftp.log");

  # Login to the target host
  $mySetup->{localhost}->login(qr/login/, qr/Password: $/, qr/$/);

  # Execute localhost's ftp command 
  $numberOfFileUploaded = $mySetup->{localhost}->ftp($ftpServerIP, $ftpUserName, $ftpPassword);

  # Release localhost's resource
  $mySetup->{localhost}->DESTROY();
}
undef $mySetup;
